package com.bilibili.api.support;

import com.bilibili.domain.exception.ConditionException;
import com.bilibili.utils.TokenUtil;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;



/**
 * projectName:com.bilibili.api.support
 *
 * @author 飞
 * @create by 2024/6/315:31
 * description:
 */
@Component
public class UserSupport {
    //获取token
    public Long getCurrentUserId() {
        ServletRequestAttributes requestAttributes =
                (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        String token = requestAttributes.getRequest().getHeader("token");
        Long userId = TokenUtil.verifyToken(token);

        if (userId<0){
            throw new ConditionException("非法用户！");
        }

        return userId;
    }
}
